Skip to content

Refactor GroupedLinear quantization dispatch - #3326

Open
negvet wants to merge 3 commits into
NVIDIA:mainfrom
negvet:refactor-grouped-quantization
Open

Refactor GroupedLinear quantization dispatch#3326
negvet wants to merge 3 commits into
NVIDIA:mainfrom
negvet:refactor-grouped-quantization

Conversation

@negvet

@negvet negvet commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Description

Move grouped quantization helpers into a dedicated module and replace separate split APIs with one. Keeps quantizer validation at construction only for CustomRecipe while skipping validation for the built-in recipes.
Followup for #2817

Type of change

  • Documentation change (change only to the documentation, either a fix or a new content)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Infra/Build change
  • Code refactoring

Changes

Please list the changes introduced in this PR:

  • Change A
  • Change B

Checklist:

  • I have read and followed the contributing guidelines
  • The functionality is complete
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Signed-off-by: Evgeny <etsykunov@nvidia.com>
@negvet
negvet requested a review from ksivaman as a code owner August 7, 2026 13:25
@negvet
negvet requested a review from zhongbozhu August 7, 2026 13:26
@greptile-apps

greptile-apps Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR extracts GroupedLinear split-quantization logic into a dedicated module and consolidates split, quantization, and bias-gradient handling behind one dispatch API.

  • Adds quantizer-driven dispatch for native, hybrid, identity, debug, and Python fallback paths.
  • Restricts grouped-quantizer compatibility validation to CustomRecipe generations.
  • Updates GroupedLinear forward and backward call sites and expands quantization equivalence and dispatch tests.

Confidence Score: 5/5

The PR appears safe to merge because no blocking failure remains.

No blocking failure remains.

Important Files Changed

Filename Overview
transformer_engine/pytorch/module/_split_quantization.py Introduces the consolidated grouped split-quantization, compatibility-validation, hybrid-dispatch, and optional bias-gradient implementation.
transformer_engine/pytorch/module/grouped_linear.py Delegates forward and backward split quantization to the new helper module and limits compatibility validation to CustomRecipe generations.
tests/pytorch/test_hybrid_quantization.py Expands coverage for native bias-gradient dispatch, hybrid source policies, validation caching, and built-in recipe behavior.
tests/pytorch/test_custom_recipe.py Strengthens GroupedLinear CustomRecipe coverage with exact forward and backward equivalence checks.
tests/pytorch/test_identity_quantizer.py Updates identity and hybrid split tests for the unified API and verifies optional bias-gradient results.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  GL["GroupedLinear forward/backward"] --> SQ["_split_quantize"]
  SQ --> P{"Quantized output?"}
  P -->|No| Plain["Cast and torch.split"]
  P -->|Yes, native bgrad| BGrad["Per-split bgrad_quantize"]
  P -->|Yes, DebugQuantizer| Debug["Debug multi-tensor quantize"]
  P -->|Yes, HybridQuantizer| Hybrid["Rowwise/columnwise split quantization"]
  P -->|Yes, native quantizer| Native["Bulk split_quantize"]
  P -->|Yes, custom/identity| Fallback["Python per-split fallback"]
  Plain --> Out["Split outputs and optional dbiases"]
  BGrad --> Out
  Debug --> Out
  Hybrid --> Out
  Native --> Out
  Fallback --> Out
Loading

Reviews (2): Last reviewed commit: "[pre-commit.ci] auto fixes from pre-comm..." | Re-trigger Greptile

@negvet

negvet commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator Author

/te-ci pytorch L1

#
# See LICENSE for license information.

"""Grouped split-quantization helpers used by :mod:`GroupedLinear`."""

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename this file to something like split quantization? It's not really a grouped quantization

# tensors (like scales), but bulk allocation shares storage across all tensors,
# so if scales can't be offloaded, nothing in the group can be offloaded.
inputmats = _split_quantize(
inputmats, _ = _grouped_quantization._split_quantize(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment for renaming

else:
input_quantizer.set_usage(rowwise=False, columnwise=True)
inputmats = _split_quantize(
inputmats, _ = _grouped_quantization._split_quantize(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment

@zhongbozhu zhongbozhu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall LGTM, just have some questions

)
return outputs, dbiases

concrete_quantizers = cast(Sequence[Quantizer], quantizers)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this cast(Sequence[Quantizer], quantizers)? feels like some extra CPU overhead?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only for the type checker, like assume there are no None elements. At runtime, it returns the same object unchanged, it does not iterate through.

@zhongbozhu

Copy link
Copy Markdown
Collaborator

/te-ci pytorch

negvet and others added 2 commits August 10, 2026 13:53
Signed-off-by: Evgeny <etsykunov@nvidia.com>
@negvet

negvet commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator Author

/te-ci pytorch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants